using System.Collections.ObjectModel;
using System.Linq;
using VisualWip.Core;
using VisualWip.Core.Columns;
using VisualWip.Core.Interfaces;

namespace VisualWip.PresentationModel.SettingsViewModels
{
    public abstract class WorkItemsSettingsViewModelBase<TColumn> : SettingsViewModelBase<TColumn> where TColumn : WorkItemsColumnBase
    {
        protected WorkItemsSettingsViewModelBase(Application application, TColumn column,
                                                    IWorkItemSizeProvider workItemSizeProvider,
                                                    IColumnTypeProvider columnTypeProvider)
            : base(application, column, columnTypeProvider)
        {
            Sizes = new ObservableCollection<WorkItemSize>(workItemSizeProvider.GetSizes());
            if (Column.WorkItemSize == null)
                Size = Sizes.First();

        }

        public WorkItemSize Size
        {
            get { return Column.WorkItemSize; }
            set
            {
                if (value != Column.WorkItemSize)
                {
                    Column.WorkItemSize = value;
                    OnPropertyChanged(this, () => Size);
                }
            }
        }

        public ObservableCollection<WorkItemSize> Sizes { get; private set; }
    }
}